﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QuanLyNhanSu
{
    public partial class From1 : Form
    {
        private SqlConnection connect;
        public From1()
        {
            InitializeComponent();
        }

        private void bt_exit_Click(object sender, EventArgs e)
        {
            doClose();
        }
        private void bt_login_Click(object sender, EventArgs e)
        {
            doCheck();
        }

        
//----------------------------- Public Class ----------------------------------//        
        // ---- Dong cua so ----//
        private void doClose()
        {
            this.Close();
        }

        // ---- Connect database ----//
        private void doConnect()
        {
            string cn = "Data Source=SUNRISE;Initial Catalog=QuanLyNhanSu;User ID=sa;Password=12345";
            try
            {
                connect = new SqlConnection(cn);
                connect.Open();
            }
            catch (Exception e)
            {
                MessageBox.Show("Connect close!");
            }
        }
        // ------ Reset ------
        private void doReset()
        {
            ccbox_username.Text = "";
            tb_pass.Text = "";
        }

        // ------ End Reset ------

        // ---- Check ID and Pass ----//
        private void doCheck()
        {
            doConnect();
            SqlCommand com = new SqlCommand("Select * from DangNhap Where ID = @id and Pass = @pass", connect);
            com.Parameters.AddWithValue("@id", ccbox_username.Text.Trim());
            com.Parameters.AddWithValue("@pass", tb_pass.Text.Trim());
            object a = com.ExecuteScalar();
            if (a != null)
            {
                FormMain main = new FormMain();
                main.Show();
                this.Visible = false;
            }
            else
                doReset(); 
        }

        private void bt_more_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Coming soon! Please Wait ^^!", "Tùy Chọn", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        
//----------------------------- End Public Class ------------------------------//        
    }
}
